program define mcre_lf
args lnf xb a0 a1 a2
tempvar prob


loc p1 "(1-(1/(1+exp(`xb'))^exp(`a2')))"

#delimit ;
quietly generate double `prob' = cond($ML_y1==1, 
	normal(`a0')+(1-normal(`a0')-normal(`a1'))*`p1', 
	1-normal(`a0')-(1-normal(`a0')-normal(`a1'))*`p1' ) 
	if $ML_samp==1;
#delimit cr

if normal(`a0')+normal(`a1') < 1 {
	quietly replace `lnf' = ln(`prob')
}
else {
	qui replace `lnf'=.
}

end
